<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Upload;
class UploadController extends Controller {
    public function index(){
        $this->display();
    }

    public function uploadImg(){
        $rootPath = C('TMPL_PARSE_STRING.__UPLOAD__');
        $updatePath = "";
        if (!empty($_POST['path'])) {
            $updatePath = $_POST['path'];
        }
        $upload = new Upload();// 实例化上传类
        $upload->maxSize = 3145728 ;// 设置附件上传大小
        $upload->exts = array('jpg');// 设置附件上传类型
        $upload->rootPath = $rootPath; // 设置附件上传根目录
        $upload->savePath = $updatePath; // 设置附件上传（子）目录
        $upload->autoSub = false;
        $upload->replace = true;
        if (!empty($_POST['file_name'])) {
            $upload->saveName = $_POST['file_name'];
        }

        // 上传文件
        $info = $upload->uploadOne($_FILES['files']);
        // var_dump($info);

        if(!$info) {// 上传错误提示错误信息
            // $rel['status'] = 0;
            // $rel['info'] = $upload->getError();
            $this->error($upload->getError());
        }else{// 上传成功 获取上传文件信息
            // $rel['status'] = 1;
            $this->ajaxReturn($info);
        }

    }
}